#ifndef __MULTITASKING_H
#define __MULTITASKING_H

#include <common/common.h>
#include <common/types.h>
#include <gdt.h>


struct CPUState
{
    uint32_t eax;
    uint32_t ebx;
    uint32_t ecx;
    uint32_t edx;

    uint32_t esi;
    uint32_t edi;
    uint32_t ebp;
/*
    uint32_t gs;
    uint32_t fs;
    uint32_t es;
    uint32_t ds;
*/
    uint32_t error;

    uint32_t eip;
    uint32_t cs;
    uint32_t eflags;
    uint32_t esp;
    uint32_t ss;
}__attribute__((packed));



class Task
{
private:
    friend class TaskManager;
    /* data */
public:
    uint8_t statck[4096];
    CPUState* cpuState;  //save last execute environment
    Task(GlobalDescriptorTable* gdt, void entryPoint());
    ~Task();
};



class TaskManager
{
private:
    /* data */
    Task* tasks[256];
    int numTasks;
    int currentTask;
public:
    TaskManager();
    ~TaskManager();
    bool AddTask(Task* task);
    CPUState* Schedule(CPUState* cpustate);
};





#endif